const jwt = require("jsonwebtoken");
const { SECRET } = require("./utils");

const test1 = {
  methods: "post",
  handle: (req, res) => {
    const token = req.header("Authorization");

    try {
      jwt.verify(token, SECRET);
      res.send({
        msg: "请求成功",
        success: true,
        status: 200,
        response: null,
      });
    } catch (e) {
      res.status(401).send({
        msg: "token已过期",
        success: false,
        status: 401,
        response: null,
      });
    }
  },
};
const test2 = {
  methods: "post",
  handle: (req, res) => {
    const token = req.header("Authorization");

    try {
      jwt.verify(token, SECRET);
      res.send({
        msg: "请求成功",
        success: true,
        status: 200,
        response: null,
      });
    } catch (e) {
      res.status(401).send({
        msg: "token已过期",
        success: false,
        status: 401,
        response: null,
      });
    }
  },
};
const test3 = {
  methods: "post",
  handle: (req, res) => {
    const token = req.header("Authorization");

    try {
      jwt.verify(token, SECRET);
      res.send({
        msg: "请求成功",
        success: true,
        status: 200,
        response: null,
      });
    } catch (e) {
      res.status(401).send({
        msg: "token已过期",
        success: false,
        status: 401,
        response: null,
      });
    }
  },
};

module.exports = {
  test1,
  test2,
  test3,
};
